#include "opencv2/core.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    //使用构造函数
    Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255));
    cout << "M = " << endl << " " << M << endl << endl;

    // 使用create函数
    Mat N;
    N.create(4, 4, CV_8UC(2));
    cout << "N = " << endl << " " << N << endl << endl;

    // 创建多维矩阵
    int sz[3] = { 2,2,2 };
    Mat L(3, sz, CV_8UC(1), Scalar::all(0));
    // 无法通过 << 打印

    // MATLAB 风格的 eye, ones 或 zero 矩阵
    Mat E = Mat::eye(4, 4, CV_64F);
    cout << "E = " << endl << " " << E << endl << endl;
    Mat O = Mat::ones(2, 2, CV_32F);
    cout << "O = " << endl << " " << O << endl << endl;
    Mat Z = Mat::zeros(3, 3, CV_8UC1);
    cout << "Z = " << endl << " " << Z << endl << endl;

    // 创建一个3x3双精度矩阵
    Mat C = (Mat_<double>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
    cout << "C = " << endl << " " << C << endl << endl;

    //  或者
#ifdef CV_CXX11
    C = (Mat_<double>({ 0, -1, 0, -1, 5, -1, 0, -1, 0 })).reshape(3);
    cout << "C = " << endl << " " << C << endl << endl;
#endif
    // clone
    Mat RowClone = C.row(1).clone();
    cout << "RowClone = " << endl << " " << RowClone << endl << endl;

    // 用随机值填充矩阵
    Mat R = Mat(3, 2, CV_8UC3);
    randu(R, Scalar::all(0), Scalar::all(255));

    // 各种输出格式
    cout << "R (default) = " << endl << R << endl << endl;
    cout << "R (python)  = " << endl << format(R, Formatter::FMT_PYTHON) << endl << endl;
    cout << "R (numpy)   = " << endl << format(R, Formatter::FMT_NUMPY) << endl << endl;
    cout << "R (csv)     = " << endl << format(R, Formatter::FMT_CSV) << endl << endl;
    cout << "R (c)       = " << endl << format(R, Formatter::FMT_C) << endl << endl;

    return 0;
}
